layui.use(['dtree'], function(){
	var form = layui.form;
	var dtree = layui.dtree;
	
	//获取父级菜单
	var menuTree = dtree.renderSelect({
		  elem: "#menuTree",
		  url: ctx+"/sys/menu/getDtreeList",
		  method: "get",
		  width: "100%", 
		  dataStyle: "layuiStyle",  
		  dataFormat: "list",  
		  response:{message:"msg",statusCode:200},  
		  initLevel: 3,
		  menubar: true, 
		  menubarTips:{
			    group:["moveDown", "moveUp","searchNode", {
			      menubarId: "clearSelectNode",  
			      icon: "dtree-icon-homefill", 
			      title: "初始化",  
			      handler: function(node, $div){ 
			    	  menuTree.menubarMethod().refreshTree();
			    	  $("#parentId").val("");
			      }
			    }]
			  },
		  selectTips: "请选择父级菜单"
	});
   dtree.on("node('menuTree')" ,function(obj){
		  $("#parentId").val(obj.param.nodeId)
   });
	  
	$("#menuAddType").initSelectDict();
	
	form.on('submit(menu-add)', function(data){
//		var param = dtree.getNowParam(menuTree);
//		data.field.parentId = param.nodeId;
	    var url = ctx + "/sys/menu/add";
	  	ajaxCommit({
			  url : url
			  ,data : data.field
			  ,successfunc: function(){ pageReload() }
		})
	    return false;
	});
	
	$("#choseIcon").click(function(){
		var title = $(this).text();
		var url = ctx+"/sys/menu/icon";
		$.get(url, {}, function(res){
			if(!isJSON(res)){
				var index = layer.open({
					type: 1,
					title: title,
					skin: 'layui-layer-rim', 
					area: ['50%', '50%'],  
					offset: ['5%', '20%'],
			        content: res,
					btn: []
				    ,maxmin: true
				});
				layer.full(index);
			}
		  });
	})
	
})